package com.zhanghp.common;

import java.io.*;
import java.util.function.BiConsumer;
import java.util.function.Function;

/**
 * <p>
 * ctrl + d终止输入指令
 *
 * @author zhanghp
 * @since 2024/3/28 16:23
 */
public class AcmUtil {

    public static void acm(BiConsumer<StreamTokenizer, PrintWriter> biConsumer) throws IOException {
        // 输入
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        // 输出
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        biConsumer.accept(in, out);
        out.flush();
        out.close();
        br.close();
    }

    public static void acm(Function<StreamTokenizer, Object> func) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);

        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        while(in.nextToken() != StreamTokenizer.TT_EOF){
            out.println(func.apply(in));
        }

        out.flush();
        br.close();
        out.close();
    }

    public static void acmMultiResult(BiConsumer<StreamTokenizer, PrintWriter> func) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);

        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        while(in.nextToken() != StreamTokenizer.TT_EOF){
            func.accept(in, out);
        }

        out.flush();
        br.close();
        out.close();
    }
}
